package com.sample.jni;

import java.nio.ByteBuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.swak.nativex.Native;

/**
 * 用于测试 JNI
 * 
 * 1. jni.h 中的申明的学习，大体知道是做什么；
 * 2. C 语言的学习；可以先学习 hadoop 下的nativeio；
 * 3. 主要是磁盘、内存、网络；
 * 
 * @author 618lf
 */
public class HelloService {

	static Logger logger = LoggerFactory.getLogger(HelloService.class);

	static {

		/**
		 * 放入： META-INF/native/
		 */
		Native.loadLibrary("libnativeio");

		/**
		 * 初始化 NativeIO
		 */
		try {
			initNative();
		} catch (Exception e) {
			logger.error("Unable to initialize NativeIO libraries", e);
		}
	}
	
	/**
	 * 定义naive方法，返回String类型
	 * @return
	 */
	public native String getStringFromC();

	/** 
	 * Initialize the JNI method ID and class ID cache
	 */
	private static native void initNative();

	/**
	 * mlock
	 * 
	 * @param buffer
	 * @param len
	 * @throws NativeIOException
	 */
	public static native void mlock_native(ByteBuffer buffer, long len) throws NativeIOException;
}
